package com.lanou.musicproject.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.ListView;

import com.alibaba.fastjson.JSON;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.lanou.musicproject.R;
import com.lanou.musicproject.adapter.RankMatterListViewAdapter;
import com.lanou.musicproject.base.BaseActivity;
import com.lanou.musicproject.bean.Rank;
import com.lanou.musicproject.bean.RankContent;
import com.lanou.musicproject.volley.VolleySingleton;
import com.squareup.picasso.Picasso;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;
/**
 * Created by dllo on 15/10/20.
 */
public class RankMatter extends BaseActivity {

    private String url ;
    private ListView rank_Matter_ListView;
    private ArrayList<RankContent.SongListEntity> data;
    private VolleySingleton volleySingleton;
    private String type;
    private RankMatterListViewAdapter adapter;
    private String imgsrc;
    private ImageView rank_content_image;
    private Rank.ContentEntity entity;
    private ImageView rank_menu;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.rank_activity);
        rank_Matter_ListView = (ListView) findViewById(R.id.rank_Matter_ListView);
        rank_content_image = (ImageView) findViewById(R.id.rank_content_image);
        Intent intent = getIntent();
        if (intent !=null) {
            entity = (Rank.ContentEntity) intent.getSerializableExtra("type");
            imgsrc = entity.getPic_s192();
            type = entity.getType();
            Log.i("lanou****",imgsrc+"55555555555"+type);
            initData();
        }


    }

    private void initData() {
            volleySingleton=VolleySingleton.getInstance(this);
        Picasso.with(this).load(imgsrc).into(rank_content_image);
        if (type != null){
        url = "http://tingapi.ting.baidu.com/v1/restserver/ting?from=" +
                "android&version=5.6.5.0&method=baidu.ting.billboard.billList&format=json&type=" +
                ""+type+"&offset=0&size=100&fields=song_id%2Ctitle%2Cauthor%2Calbum_title%2Cpic_big%2Cpic_small%2Chavehigh%2Call_rate%2Ccharge%2Chas_mv_mobile%2Clearn%2Csong_source%2Ckorean_bb_song";
            JsonObjectRequest jr= new JsonObjectRequest(url, null, new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                      String str = response.toString();

                    RankContent rankContent = JSON.parseObject(str, RankContent.class);
                        data = rankContent.getSong_list();
                    adapter = new RankMatterListViewAdapter(RankMatter.this,data);
                    rank_Matter_ListView.setAdapter(adapter);


                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            });

            volleySingleton.addQueue(jr);
        }
    }


}
